home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / COLMNHDR.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  7KB  |  262 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.10  $
  6. //
  7. // Definition of class TColumnHeader and helper classes
  8. //----------------------------------------------------------------------------
  9. #if !defined(OWL_COLMNHDR_H)
  10. #define OWL_COLMNHDR_H
  11.  
  12. #if !defined(OWL_COMMCTRL_H)
  13. # include <owl/commctrl.h>
  14. #endif
  15.  
  16. #if defined(BI_NAMESPACE)
  17. namespace OWL {
  18. #endif
  19.  
  20. class _OWLCLASS THdrItem;
  21. class _OWLCLASS THdrNotify;
  22. class _OWLCLASS TColumnHeader;
  23.  
  24. #if !defined(HDI_ALL)   // Mentioned in docs. but missing from headers
  25. # define HDI_ALL (HDI_BITMAP|HDI_FORMAT|HDI_HEIGHT|HDI_LPARAM|HDI_TEXT|HDI_WIDTH)
  26. #endif
  27.  
  28. // Generic definitions/compiler options (eg. alignment) preceeding the 
  29. // definition of classes
  30. #include <services/preclass.h>
  31.  
  32. //
  33. // class THdrItem
  34. // ~~~~~ ~~~~~~~~
  35. // THdrItem contains information about an item in a header control.
  36. //
  37. class _OWLCLASS THdrItem : public HD_ITEM {
  38.   public:
  39.     // Constructors which create 'THdrItem' structures to be used
  40.     // for adding, inserting or updating a header control's item
  41.     // 'str' specifies the text/title of the item; 'hbm' specifies a handle
  42.     // to a bitmap to be used in the item.
  43.     //
  44.     THdrItem(const char far* str);
  45.     THdrItem(const char far* str, HBITMAP hbm);
  46.     THdrItem(HBITMAP hbm);
  47.  
  48.     // Constructors used primarily to construct a 'THdrItem' structure
  49.     // which will be used to retrieve information about an item within
  50.     // a header control. 'buffer' specifies the location to receive the
  51.     // item's title and 'len' indicates the size of that buffer. The 'msk'
  52.     // flags indicates which members of the structure should be updated.
  53.     //
  54.     THdrItem(char far* buffer, int len, uint msk = HDI_TEXT);
  55.     THdrItem(uint msk = 0);
  56.  
  57.     // Methods to set the data members of the HD_ITEM structure.
  58.     //
  59.     void          SetText(const char far* str);
  60.     void          SetBitmap(HBITMAP hbm);
  61.     void          SetWidth(int cx);
  62.     void          SetHeight(int cy);
  63.     void          SetItemData(TParam2 data);
  64.     void          SetMask(int msk);
  65.  
  66.     static  void  SetDefStringSize(int size);
  67.     static  void  SetDefBitmapSize(int size);
  68.     
  69.   protected:
  70.     static  int  DefStringItemSize;
  71.     static  int  DefBitmapItemSize;
  72. };
  73.  
  74.  
  75. //
  76. // class THeaderHitTestInfo
  77. // ~~~~~ ~~~~~~~~~~~~~~~~~~
  78. // THeaderHitTestInfo contains hittest information for the header control.
  79. // It is used with the TColumnHeader::HitTest method.
  80. //
  81. class THeaderHitTestInfo : public HD_HITTESTINFO {
  82.   public:
  83.     THeaderHitTestInfo(const TPoint& pt);
  84.     THeaderHitTestInfo(int x, int y);
  85. };
  86.  
  87. //
  88. // class TColumnHeader
  89. // ~~~~~ ~~~~~~~~~~~~~
  90. //  TColumnHeader encapsulates the 'header control', a window
  91. //  usually positioned above columns of text or numbers.
  92. //
  93.  
  94. #if defined(BI_NAMESPACE)
  95. } // namespace OWL
  96. #endif
  97. #include <classlib/arrays.h>
  98. #if defined(BI_NAMESPACE)
  99. namespace OWL {
  100. #endif
  101.  
  102. class _OWLCLASS TColumnHeader : public TControl {
  103.   public:
  104.     TColumnHeader(TWindow* parent,
  105.                   int             id,
  106.                   int x, int y, int w, int h,
  107.                   TModule*        module = 0);
  108.  
  109.     TColumnHeader(TWindow* parent, int resourceId, TModule* module = 0);
  110.     ~TColumnHeader();
  111.  
  112.     // Position Column Header
  113.     //
  114.     bool          Layout(TRect& boundingRect, WINDOWPOS& winPos);
  115.     bool          Layout(uint swpFlags = 0);
  116.  
  117.     // Column Header attributes
  118.     //
  119.     int           GetCount() const;
  120.  
  121.     // Operations on individual column header items
  122.     //
  123.     int           Add(const THdrItem& item);
  124.     int           Insert(const THdrItem& item, int index);
  125.     bool          Delete(int index);
  126.     bool          GetItem(THdrItem&, int index, uint mask = 0);
  127.     bool          SetItem(const THdrItem& itemInfo, int index);
  128.  
  129.     // Hit-testing
  130.     //
  131.     int           HitTest(THeaderHitTestInfo& ht);
  132.  
  133.     // Override virtual method to save/restore contents of columnHeader
  134.     //
  135.     uint          Transfer(void* buffer, TTransferDirection direction);
  136.  
  137.   protected:
  138.     // Override TWindow virtual member functions
  139.     //
  140.     char far*     GetClassName();
  141.  
  142. #if !defined(OWL_NATIVECTRL_ALWAYS)
  143.   public:
  144.     static void SetNativeUse(TNativeUse nu);
  145.  
  146.   protected_data:
  147.     static TNativeUse ClassNativeUse;
  148.  
  149.   protected:
  150.     void Paint(TDC &dc,bool erase,TRect &rect);
  151.     void EvLButtonUp(uint modKeys,TPoint &point);
  152.     void EvMouseMove(uint modKeys,TPoint &point);
  153.     void EvLButtonDblClk(uint modKeys,TPoint &point);
  154.     void EvLButtonDown(uint modKeys,TPoint &point);
  155.     bool EvSetCursor(HWND hWndCursor,uint hitTest,uint mouseMsg);
  156.     void EvSetFont(HFONT hFont,bool redraw);
  157.     HFONT EvGetFont();
  158.  
  159.   private:
  160.     void InitCtl();
  161.     void CleanupCtl();
  162.     LRESULT SendNotify(uint code,int item);
  163.  
  164.     // Internal tracking functions
  165.     //
  166.     void TrackLine(int pos);
  167.     void BeginTrack(const TPoint &point,int iItem);
  168.     void Track(const TPoint &point);
  169.     void EndTrack();
  170.  
  171.     TFont *Font;
  172.  
  173.     class _OWLCLASS TItem: public HD_ITEM {
  174.     public:
  175.       TItem();
  176.         TItem(const HD_ITEM &other);
  177.         ~TItem();
  178.         TItem &operator=(const TItem &other);
  179.       bool operator==(const TItem &other) const;
  180.  
  181.     private:
  182.       void Cleanup();
  183.         void Init(const HD_ITEM &other);
  184.     };
  185.  
  186. #if defined(BI_NAMESPACE)
  187.     ClassLib::TArrayAsVector<TItem> Item;
  188. #else
  189.     TArrayAsVector<TItem> Item;  
  190. #endif
  191.   
  192.     int HotItem;    // item currently clicked or tracked
  193.     enum TOperation { // current operation on hot item
  194.       CLICKING,
  195.       TRACKING,
  196.       NONE
  197.     } Operation;
  198.  
  199.     // for clicking
  200.     int Pressed;
  201.     // for tracking
  202.     int TrackStart;
  203.     int TrackSize;
  204.     TPoint TrackPoint;
  205.  
  206.   DECLARE_RESPONSE_TABLE(TColumnHeader);
  207. #endif
  208.  
  209.   private:
  210.     // Hidden to prevent accidental copying or assignment
  211.     //
  212.     TColumnHeader(const TColumnHeader&);
  213.     TColumnHeader& operator =(const TColumnHeader&);
  214.  
  215.   DECLARE_STREAMABLE(_OWLCLASS, TColumnHeader, 1);
  216. };
  217.  
  218.  
  219. // Generic definitions/compiler options (eg. alignment) following the 
  220. // definition of classes
  221. #include <services/posclass.h>
  222.  
  223. #if defined(BI_NAMESPACE)
  224. } // namespace OWL
  225. #endif
  226.  
  227. //----------------------------------------------------------------------------
  228. // Inline implementations
  229. //
  230.  
  231. //
  232. // Updates the mask member of the structure. The latter indicates
  233. // which other members of the structure contain valid data.
  234. //
  235. inline void THdrItem::SetMask(int msk)
  236. {
  237.   mask = msk;
  238. }
  239.  
  240. //
  241. // Initializes the client ooordinates being hit-tested with the 
  242. // specified TPoint parameter.
  243. //
  244. inline THeaderHitTestInfo::THeaderHitTestInfo(const TPoint& point)
  245. {
  246.   pt.x = point.x;
  247.   pt.y = point.y;
  248. }
  249.  
  250. //
  251. // Initializes the client ooordinates being hit-tested with the 
  252. // specified 'x' and 'y' locations.
  253. //
  254. inline THeaderHitTestInfo::THeaderHitTestInfo(int x, int y)
  255. {
  256.   pt.x = x;
  257.   pt.y = y;
  258. }
  259.  
  260.  
  261. #endif  // OWL_COLMNHDR_H
  262.